<?php

class Admin_Form_Confirmation extends My_FormAdmin {

    protected $rejectUrl = null;


    public function init() {
        parent::init();
        $this->setTitle($this->translate('XXX_ADMIN_CONFITMATION_FORM_TITLE'));
        
        $content = new My_Form_Element_Content('content');
        $content->setValue($this->translate('XXX_ADMIN_CONFIRMATION_FORM_CONTENT_DEFAULT'));
        $this->addElement($content);
        
        $this->addElement('hidden', 'id');

        $this->addSubmitElement()->setLabel(_('XXX_ADMIN_CONFIRMATION_YES'));

    }
    
    public function isConfirmed(array $data = null, $autoRedirect = true) {
        if($data != null) {
            $this->populate($data);
        }
        $result = $this->getSubmitElement()->isChecked();
        if(!$result && $autoRedirect) {
            $url = $this->rejectUrl;
            if($url == null) {
                $url = $_SERVER['HTTP_REFERER'];
            }
            if($url == null) {
                $url = $this->view->url(array('action' => 'index'));
            }
            My_Utils::redirect($url);
            return false;
        }
        return $result;
    }
    
    public function getRejectUrl() {
        return $this->rejectUrl;
    }

    public function setRejectUrl($rejectUrl) {
        $this->rejectUrl = $rejectUrl;
    }



}

